// 1.Throwable: 是一场体系顶层类两个子类: Error和Exception
//      Error: 是Java虚拟机无法解决的严重问题
//      Ecepriont: 通过代码进行处理，使程序继续执行
//          运行时异常(非受查异常)
//          编译时异常(受查异常)

class Person implements Cloneable{
    public String name;

    public Person(String name) {
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class exception {

    //  2.throws: 声明异常，表示当前方法不处理异常交给调用者
    public static void test1() throws CloneNotSupportedException
    {
        Person person1 = new Person("张三");
        Person person2 = (Person) person1.clone();
    }

    public static void func() throws CloneNotSupportedException
    {
        int a = 10;
        if(a==10)
        {
            //3.throw: 用来抛出异常
            throw new CloneNotSupportedException("hahaha");
        }
    }
    public static void test2()
    {
        try
        {
            func();
        }catch (CloneNotSupportedException e)
        {
            throw new RuntimeException(e);
        }
    }

    public static void test3()
    {
        try {
            System.out.println(10/0);
        }
        //4.|: 可以同时捕获多个
        catch (NullPointerException | ArithmeticException e)
        {
            e.printStackTrace();
            System.out.println("我来处理Arithmetic异常了");
        }
    }

    //5.自定义异常:
    //   自定义运行时异常: extends RuntimeException
    //   自定义编译时异常: extends Exception
    class myException extends RuntimeException
    {
        public myException(String message) {
            super(message);
        }
    }

    public void test4()
    {
        try
        {
            func();
        }catch (CloneNotSupportedException e)
        {
            throw new RuntimeException(e);
        }
        //6.finally: finally中的代码一定会执行
        finally {
            System.out.println("666");
        }
    }
    public static void main(String[] args) {
//        test1();
//        test2();
        test3();
    }

}
